package com.example.foo.admin.task;

import java.math.BigDecimal;
import java.time.LocalDate;

import com.example.foo.account.AccountHelper;
import com.example.foo.ftt.FttLevel;
import com.example.foo.ftt.service.FttProfitService;
//日分红预处理生成每个级别明天的分红初始化数据，状态为等待，金额为0
@org.springframework.stereotype.Component("fttProfitPendingTask")
public class FttProfitPendingTask {

	private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(getClass());

	private final FttProfitService fttProfitService;

	public FttProfitPendingTask(FttProfitService fttProfitService) {
		this.fttProfitService = fttProfitService;
	}

	public void execute(Integer offsetDay) throws Exception {
		Integer periodDay = AccountHelper.toPeriodDay(LocalDate.now().plusDays(offsetDay));

		FttLevel[] fttLevels = FttLevel.values();
		BigDecimal totalMoney = BigDecimal.ZERO;
		for (FttLevel fttLevel : fttLevels) {
			if (fttLevel == FttLevel.F0) {
				continue;
			}

			fttProfitService.createFttProfitPending(fttLevel, totalMoney, periodDay);
		}

		log.info("DONE!");
	}

}
